home *** CD-ROM | disk | FTP | other *** search
/ Aminet 40 / Aminet 40 (2000)(Schatztruhe)[!][Dec 2000].iso / Aminet / dev / c / ExtrasLib.lha / ExtrasLib / Source / AddNNStr.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-09-30  |  1.8 KB  |  110 lines

  1. #include <clib/extras/nnstring_protos.h>
  2. #include <string.h>
  3. #include <proto/exec.h>
  4.  
  5. /****** extras.lib/nns_AddNNStr ******************************************
  6. *
  7. *   NAME
  8. *       nns_AddNNStr -- append a normal string to a NNString.
  9. *
  10. *   SYNOPSIS
  11. *       NewNNStr=nns_AddNNStr(NNStr,New)
  12. *
  13. *       STRPTR nns_AddNNStr(STRPTR, STRPTR);
  14. *
  15. *   FUNCTION
  16. *       
  17. *
  18. *   INPUTS
  19. *       NNStr - an existing NNString or NULL, if NULL
  20. *           the function converts str into an NNString.
  21. *       New - a regular NULL terminated string.
  22. *
  23. *   RESULT
  24. *       A new NNString or NULL, NNStr *WILL* be freed
  25. *       regardless of result.  if New is NULL, NNStr will
  26. *       be returned.
  27. *
  28. *   EXAMPLE
  29. *
  30. *   NOTES
  31. *
  32. *   BUGS
  33. *
  34. *   SEE ALSO
  35. *
  36. ******************************************************************************
  37. *
  38. */
  39.  
  40.  
  41. STRPTR nns_AddNNStr(STRPTR NNStr, STRPTR New)
  42. {
  43.   STRPTR rv;
  44.   LONG nnlen, newlen;
  45.  
  46.  
  47.   if(New)
  48.   {
  49.     newlen  =strlen(New)+1;
  50.   
  51.     if(NNStr)
  52.     {
  53.       nnlen=nns_NNStrLen(NNStr);
  54.          
  55.       if(rv=AllocVec(nnlen+newlen+1,0))
  56.       {
  57.         CopyMem(NNStr ,rv        ,nnlen);
  58.         CopyMem(New   ,rv+nnlen-1  ,newlen);
  59.         rv[nnlen+newlen-1]=0; 
  60.       }
  61.       FreeVec(NNStr);
  62.     }
  63.     else
  64.     {
  65.       if(rv=AllocVec(newlen+1,0))
  66.       {
  67.         CopyMem(New   ,rv  ,newlen);
  68.         rv[newlen]=0; 
  69.       }
  70.     }
  71.   }
  72.   else
  73.     rv=NNStr;
  74.     
  75.   return(rv);
  76. }
  77.  
  78.  
  79. /****** Macro/nns_ProcessNNStr ******************************************
  80. *
  81. *   NAME
  82. *       nns_ProcessNNStr(NNStr, Str)
  83. *
  84. *   SYNOPSIS
  85. *       nns_ProcessNNStr(NNStr, Str)
  86. *
  87. *   FUNCTION
  88. *
  89. *   INPUTS
  90. *
  91. *   RESULT
  92. *
  93. *   EXAMPLE
  94. *       STRPTR NNStr, str;
  95. *       
  96. *       ProcessNNStr(NNStr,str)
  97. *       {
  98. *         printf("%s\n",str);
  99. *       }
  100. *
  101. *   NOTES
  102. *
  103. *   BUGS
  104. *
  105. *   SEE ALSO
  106. *
  107. ******************************************************************************
  108. *
  109. */
  110.